﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSSystem.BLL;

namespace MobileShop
{
    public partial class ChangePass : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (SessionUser == null || SessionUser.RowCount == 0)
                this.Response.Redirect("Login.aspx?url=MyAccount.aspx");
            if(!IsPostBack)
                PageMap = string.Format("My Account[{0}]|Change Password[{1}]", this.ResolveUrl("~/MyAccount.aspx"), this.ResolveUrl("~/ChangePass.aspx"));
        }

        protected void btnUpdate_OnClick(object obj, EventArgs e)
        {
            try
            {
                Customers cust = new Customers();
                cust.LoadByPrimaryKey(View_Customers.GetCurrentUser().ID);
                cust.Password = POSSystem.BLL.Utilities.CreateMD5Hash(txtNewPassword.Text);
                cust.LastModifiedDate = DateTime.UtcNow.AddHours(SystemVariables.SysVars.TimeZone);
                cust.Save();
                lblNote.Visible = true;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("ChangePass.aspx.cs", "btnUpdate_OnClick", ex.Message + ex.StackTrace);
            }
        }
    }
}